import java.util.*;

class CalendarSeekerRunner {
    public static void main(String[] args) {
        runTests();
        
        String dateAsString = getDateFromSystemInAsString();
        Date date = new Date();
        date.parse(dateAsString);
        if (date.isValid()) {
            CalendarSeeker calendarSeeker = new CalendarSeeker(date);
            System.out.println("Result: " + calendarSeeker.getDayOfWeek());
        } else {
            System.out.println("Invalid date format! Please enter date as follows: dd/mm/yyyy");
        }  
    }
    
    private static void runTests() {
        System.out.println("Testing of dates after 2000:");
        testCalentarSeeker("18/01/2014", DayOfWeek.Saturday);
        testCalentarSeeker("19/01/2014", DayOfWeek.Sunday);
        testCalentarSeeker("20/01/2014", DayOfWeek.Monday);
        testCalentarSeeker("01/01/2000", DayOfWeek.Saturday);
        testCalentarSeeker("31/12/2000", DayOfWeek.Sunday);
        System.out.println("Testing of dates before 2000:");
        testCalentarSeeker("01/01/1999", DayOfWeek.Friday);
        testCalentarSeeker("31/12/1999", DayOfWeek.Friday);
        testCalentarSeeker("06/06/1989", DayOfWeek.Tuesday);    
    }
    
    private static void testCalentarSeeker(String inputDate, DayOfWeek expectedDay) {
        Date date = new Date();
        date.parse(inputDate);
        CalendarSeeker calendarSeeker = new CalendarSeeker(date);
        DayOfWeek actualDay = calendarSeeker.getDayOfWeek();
        System.out.println("Day of week for " + inputDate + ": " + actualDay);
        if (actualDay != expectedDay) {
            System.err.println("Calculation of day for input date ["+inputDate
                    +"] failed. Expected ["+expectedDay+"], got ["+actualDay+"]");
        }
    }
    
    private static String getDateFromSystemInAsString() { 
        System.out.print("Enter a date in dd/mm/yyyy format: ");
        Scanner in = new Scanner(System.in);
        String result = in.next();
        in.close();        
        return result;
    }
}